import org.apache.avro.generic.GenericData;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class ReadFile {
    public static void main(String[] args) throws IOException {
        if(args.length == 0){
            System.out.println("创建失败，请传入一个路径参数指定要读取的文件");
            return;
        }
        String feilePath = args[0];
        System.out.println("传入的名字是:"+feilePath);

        //1.创建词汇表Configuration类型的对象
        Configuration conf =  new Configuration();
        conf.set("fs.defaultFS","hdfs://20210322045-master:9000");

        FileSystem fs = FileSystem.get(conf);
        FSDataInputStream fsDataInputStream = fs.open(new Path(feilePath));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fsDataInputStream));

        //读取文件第一行字符串，如果返回null，表明已经读取到文件的末尾
        String nextLine = bufferedReader.readLine();

        //如果没有读取到末尾，则继续读取
        while (null != nextLine){
            //将读取到的数据输出到控制台
            System.out.println(nextLine);
            nextLine = bufferedReader.readLine();
        }
        fs.close();
    }
}
